package io.xdag.block.model;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import org.apache.commons.lang3.ArrayUtils;

import io.xdag.io.Struct;

public class XdagAmount extends Struct implements Serializable {

	private static final long serialVersionUID = 1L;
	
	public Unsigned64 amount = new Unsigned64();

	private ByteBuffer bb;
	
	public XdagAmount() {};
	
	public XdagAmount(Byte[] bytes) {
		this.setByteBuffer(bytes);
	}
	
	@Override
	public boolean isPacked() {
		return true;//对齐问题
	}
	
	/**
	 * 初始化对象buffer
	 * @param bytes
	 */
	public void setByteBuffer(Byte[] bytes) {
		byte[] bs = ArrayUtils.toPrimitive(bytes);
		bb = ByteBuffer.wrap(bs);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		this.setByteBuffer(bb, 0);
	}
	
	/**
	 * 初始化对象buffer
	 * @param bytes
	 */
	public void setByteBuffer(byte[] bytes) {
		bb = ByteBuffer.wrap(bytes);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		this.setByteBuffer(bb, 0);
	}
	
	@Override
	public ByteOrder byteOrder() {
		return ByteOrder.LITTLE_ENDIAN;
	}
	
	public Unsigned64 getAmount() {
		return amount;
	}

	public void setAmount(Unsigned64 amount) {
		this.amount = amount;
	}

	public ByteBuffer getBb() {
		return bb;
	}

	public void setBb(ByteBuffer bb) {
		this.bb = bb;
	}


	@Override
	public String toString() {
		return "XdagAmount [amount=" + amount + ", bb=" + bb + "]";
	}

	
}
